<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Proxy 与 Reflect</title>
</head>
<body>
  <script>
    const user = {
      name: 'tom',
      age: 12
    }

    // 为user创建一个对应的代理对象
    const proxy = new Proxy(user, {
      // 监视读取属性
      get(target, property) {
        console.log('监视到了读取属性')
        return Reflect.get(target, property)
      },
      // 监视修改或添加属性
      set(target, property, value) {
        console.log('监视到了修改或添加属性')
        return Reflect.set(target, property, value)
      },
      // 监视删除属性
      deleteProperty(target, property) {
        console.log('监视到了删除属性')
        return Reflect.deleteProperty(target, property)
      },
    })
    // 通过代理对象来操作目标数据对象
    // 读
    // console.log(proxy.name) 
    // 修改
    // proxy.name += '--'
    // 添加
    // proxy.sex = '男'
    // 删除
    delete proxy.name


    console.log(user)


  </script>
</body>
</html>